package com.bjc.netty.c3;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @program: nettypro
 * @description: jdk  future  同步等待 异步执行
 * @author: bjc
 * @create: 2021-09-23 21:46
 */
@Slf4j
public class TestJdkFuture {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //1.创建线程池
        ExecutorService service = Executors.newFixedThreadPool(2);
        //2.提交任务
        Future<Integer> future = service.submit(() -> {
            log.debug("执行计算");
            TimeUnit.SECONDS.sleep(1L);
            return 50;
        });
        //3.主线程通过future来获取结果
        log.debug("等待结果");
        log.debug("结果是：{}",future.get());
    }
}
